package com.example.iotmanagerment26.controller;

import com.example.iotmanagerment26.domain.Data;
import com.example.iotmanagerment26.domain.JsonData;
import com.example.iotmanagerment26.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 作者：太难猫
 * 创建时间： 2025/6/13 10:16
 */
@RestController
@CrossOrigin
@RequestMapping(value="/v1/data")
public class  DataController {
    @Autowired
    DataService dataService;

    @GetMapping("selectDataByName")
    public JsonData selectDataByName(String name){
        Data result=dataService.selectDataByName(name);
        if(result!=null)
            return new JsonData(1,result,"查询成功");
        else
            return new JsonData(0,null,"没有数据");
    }

    // 查看设备历史数据
    @GetMapping("/selectHisDataByName")
    public JsonData selectHisDataByName(String name){
        List<Data> results= dataService.selectHisDataByName(name);
        if(results!=null){
            return new JsonData(1,results,"查询成功");
        }else
            return new JsonData(0,results,"查询失败");
    }

}